package com.sixth.controller;

import com.sixth.bean.MarketUser;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.bean.common.BaseResultVo;
import com.sixth.constant.Constant;
import com.sixth.service.WxFootprintService;
import com.sixth.util.MarketInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName WxFootprintController
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/11 19:36
 **/
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {

    @Autowired
    WxFootprintService wxFootprintService;

    /**
     * 显示用户的分页足迹信息
     * @Param BasePageInfo
     * @Return BaseRespVo
     * @author XiaoWJ
     * @date 2022/9/11 20:23
     */

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo basePageInfo) {

        MarketUser marketUser = MarketInfoUtil.getMarketUser();

        Object result = wxFootprintService.list(basePageInfo, marketUser.getId());

        return BaseRespVo.ok(result);
    }

    /**
     * 删除足迹
     * @Param  足迹id
     * @Return BaseResultVo
     * @author XiaoWJ
     * @date   2022/9/11 20:35
     */

    @RequestMapping("delete")
    public BaseResultVo delete(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");
        MarketUser marketUser = MarketInfoUtil.getMarketUser();
        int code = wxFootprintService.delete(id, marketUser.getId());

        if (code == Constant.OK) {
            return BaseResultVo.ok();
        }
        return BaseResultVo.error("失败");

    }

}
